using System; 
using System.Text; 
using System.Data;
using System.Data.SqlClient;
using System.Data.Common;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Configuration; 
using System.Xml; 
using System.Xml.Serialization;
using SubSonic; 
using SubSonic.Utilities;

namespace Adex
{
	/// <summary>
	/// Strongly-typed collection for the NewsTemplate class.
	/// </summary>
	[Serializable]
	public partial class NewsTemplateCollection : ActiveList<NewsTemplate, NewsTemplateCollection> 
	{	   
		public NewsTemplateCollection() {}

	}

	/// <summary>
	/// This is an ActiveRecord class which wraps the NewsTemplate table.
	/// </summary>
	[Serializable]
	public partial class NewsTemplate : ActiveRecord<NewsTemplate>
	{
		#region .ctors and Default Settings
		
		public NewsTemplate()
		{
		  SetSQLProps();
		  InitSetDefaults();
		  MarkNew();
		}

		
		private void InitSetDefaults() { SetDefaults(); }

		
		public NewsTemplate(bool useDatabaseDefaults)
		{
			SetSQLProps();
			if(useDatabaseDefaults)
				ForceDefaults();
			MarkNew();
		}

		public NewsTemplate(object keyID)
		{
			SetSQLProps();
			InitSetDefaults();
			LoadByKey(keyID);
		}

		 
		public NewsTemplate(string columnName, object columnValue)
		{
			SetSQLProps();
			InitSetDefaults();
			LoadByParam(columnName,columnValue);
		}

		
		protected static void SetSQLProps() { GetTableSchema(); }

		
		#endregion
		
		#region Schema and Query Accessor
		public static Query CreateQuery() { return new Query(Schema); }

		
		public static TableSchema.Table Schema
		{
			get
			{
				if (BaseSchema == null)
					SetSQLProps();
				return BaseSchema;
			}

		}

		
		private static void GetTableSchema() 
		{
			if(!IsSchemaInitialized)
			{
				//Schema declaration
				TableSchema.Table schema = new TableSchema.Table("NewsTemplate", TableType.Table, DataService.GetInstance("Adex"));
				schema.Columns = new TableSchema.TableColumnCollection();
				schema.SchemaName = @"dbo";
				//columns
				
				TableSchema.TableColumn colvarTemplateID = new TableSchema.TableColumn(schema);
				colvarTemplateID.ColumnName = "TemplateID";
				colvarTemplateID.DataType = DbType.Int32;
				colvarTemplateID.MaxLength = 0;
				colvarTemplateID.AutoIncrement = true;
				colvarTemplateID.IsNullable = false;
				colvarTemplateID.IsPrimaryKey = true;
				colvarTemplateID.IsForeignKey = false;
				colvarTemplateID.IsReadOnly = false;
				colvarTemplateID.DefaultSetting = @"";
				colvarTemplateID.ForeignKeyTableName = "";
				schema.Columns.Add(colvarTemplateID);
				
				TableSchema.TableColumn colvarTemplateName = new TableSchema.TableColumn(schema);
				colvarTemplateName.ColumnName = "TemplateName";
				colvarTemplateName.DataType = DbType.String;
				colvarTemplateName.MaxLength = 200;
				colvarTemplateName.AutoIncrement = false;
				colvarTemplateName.IsNullable = true;
				colvarTemplateName.IsPrimaryKey = false;
				colvarTemplateName.IsForeignKey = false;
				colvarTemplateName.IsReadOnly = false;
				colvarTemplateName.DefaultSetting = @"";
				colvarTemplateName.ForeignKeyTableName = "";
				schema.Columns.Add(colvarTemplateName);
				
				TableSchema.TableColumn colvarPicture1 = new TableSchema.TableColumn(schema);
				colvarPicture1.ColumnName = "Picture1";
				colvarPicture1.DataType = DbType.String;
				colvarPicture1.MaxLength = 200;
				colvarPicture1.AutoIncrement = false;
				colvarPicture1.IsNullable = true;
				colvarPicture1.IsPrimaryKey = false;
				colvarPicture1.IsForeignKey = false;
				colvarPicture1.IsReadOnly = false;
				colvarPicture1.DefaultSetting = @"";
				colvarPicture1.ForeignKeyTableName = "";
				schema.Columns.Add(colvarPicture1);
				
				TableSchema.TableColumn colvarPicture2 = new TableSchema.TableColumn(schema);
				colvarPicture2.ColumnName = "Picture2";
				colvarPicture2.DataType = DbType.String;
				colvarPicture2.MaxLength = 200;
				colvarPicture2.AutoIncrement = false;
				colvarPicture2.IsNullable = true;
				colvarPicture2.IsPrimaryKey = false;
				colvarPicture2.IsForeignKey = false;
				colvarPicture2.IsReadOnly = false;
				colvarPicture2.DefaultSetting = @"";
				colvarPicture2.ForeignKeyTableName = "";
				schema.Columns.Add(colvarPicture2);
				
				TableSchema.TableColumn colvarPicture3 = new TableSchema.TableColumn(schema);
				colvarPicture3.ColumnName = "Picture3";
				colvarPicture3.DataType = DbType.String;
				colvarPicture3.MaxLength = 200;
				colvarPicture3.AutoIncrement = false;
				colvarPicture3.IsNullable = true;
				colvarPicture3.IsPrimaryKey = false;
				colvarPicture3.IsForeignKey = false;
				colvarPicture3.IsReadOnly = false;
				colvarPicture3.DefaultSetting = @"";
				colvarPicture3.ForeignKeyTableName = "";
				schema.Columns.Add(colvarPicture3);
				
				TableSchema.TableColumn colvarDateAdded = new TableSchema.TableColumn(schema);
				colvarDateAdded.ColumnName = "DateAdded";
				colvarDateAdded.DataType = DbType.DateTime;
				colvarDateAdded.MaxLength = 0;
				colvarDateAdded.AutoIncrement = false;
				colvarDateAdded.IsNullable = true;
				colvarDateAdded.IsPrimaryKey = false;
				colvarDateAdded.IsForeignKey = false;
				colvarDateAdded.IsReadOnly = false;
				colvarDateAdded.DefaultSetting = @"";
				colvarDateAdded.ForeignKeyTableName = "";
				schema.Columns.Add(colvarDateAdded);
				
				TableSchema.TableColumn colvarDateModified = new TableSchema.TableColumn(schema);
				colvarDateModified.ColumnName = "DateModified";
				colvarDateModified.DataType = DbType.DateTime;
				colvarDateModified.MaxLength = 0;
				colvarDateModified.AutoIncrement = false;
				colvarDateModified.IsNullable = true;
				colvarDateModified.IsPrimaryKey = false;
				colvarDateModified.IsForeignKey = false;
				colvarDateModified.IsReadOnly = false;
				colvarDateModified.DefaultSetting = @"";
				colvarDateModified.ForeignKeyTableName = "";
				schema.Columns.Add(colvarDateModified);
				
				BaseSchema = schema;
				//add this schema to the provider
				//so we can query it later
				DataService.Providers["Adex"].AddSchema("NewsTemplate",schema);
			}

		}

		#endregion
		
		#region Props
		
		  
		[XmlAttribute("TemplateID")]
		public int TemplateID 
		{
			get { return GetColumnValue<int>("TemplateID"); }

			set { SetColumnValue("TemplateID", value); }

		}

		  
		[XmlAttribute("TemplateName")]
		public string TemplateName 
		{
			get { return GetColumnValue<string>("TemplateName"); }

			set { SetColumnValue("TemplateName", value); }

		}

		  
		[XmlAttribute("Picture1")]
		public string Picture1 
		{
			get { return GetColumnValue<string>("Picture1"); }

			set { SetColumnValue("Picture1", value); }

		}

		  
		[XmlAttribute("Picture2")]
		public string Picture2 
		{
			get { return GetColumnValue<string>("Picture2"); }

			set { SetColumnValue("Picture2", value); }

		}

		  
		[XmlAttribute("Picture3")]
		public string Picture3 
		{
			get { return GetColumnValue<string>("Picture3"); }

			set { SetColumnValue("Picture3", value); }

		}

		  
		[XmlAttribute("DateAdded")]
		public DateTime? DateAdded 
		{
			get { return GetColumnValue<DateTime?>("DateAdded"); }

			set { SetColumnValue("DateAdded", value); }

		}

		  
		[XmlAttribute("DateModified")]
		public DateTime? DateModified 
		{
			get { return GetColumnValue<DateTime?>("DateModified"); }

			set { SetColumnValue("DateModified", value); }

		}

		
		#endregion
		
		
		#region PrimaryKey Methods
		
		public Adex.CompanyCollection CompanyRecords()
		{
			return new Adex.CompanyCollection().Where(Company.Columns.NewsTemplateID, TemplateID).Load();
		}

		#endregion
		
			
		
		//no foreign key tables defined (0)
		
		
		
		//no ManyToMany tables defined (0)
		
		#region ObjectDataSource support
		
		
		/// <summary>
		/// Inserts a record, can be used with the Object Data Source
		/// </summary>
		public static void Insert(string varTemplateName,string varPicture1,string varPicture2,string varPicture3,DateTime? varDateAdded,DateTime? varDateModified)
		{
			NewsTemplate item = new NewsTemplate();
			
			item.TemplateName = varTemplateName;
			
			item.Picture1 = varPicture1;
			
			item.Picture2 = varPicture2;
			
			item.Picture3 = varPicture3;
			
			item.DateAdded = varDateAdded;
			
			item.DateModified = varDateModified;
			
		
			if (System.Web.HttpContext.Current != null)
				item.Save(System.Web.HttpContext.Current.User.Identity.Name);
			else
				item.Save(System.Threading.Thread.CurrentPrincipal.Identity.Name);
		}

		
		/// <summary>
		/// Updates a record, can be used with the Object Data Source
		/// </summary>
		public static void Update(int varTemplateID,string varTemplateName,string varPicture1,string varPicture2,string varPicture3,DateTime? varDateAdded,DateTime? varDateModified)
		{
			NewsTemplate item = new NewsTemplate();
			
				item.TemplateID = varTemplateID;
				
				item.TemplateName = varTemplateName;
				
				item.Picture1 = varPicture1;
				
				item.Picture2 = varPicture2;
				
				item.Picture3 = varPicture3;
				
				item.DateAdded = varDateAdded;
				
				item.DateModified = varDateModified;
				
			item.IsNew = false;
			if (System.Web.HttpContext.Current != null)
				item.Save(System.Web.HttpContext.Current.User.Identity.Name);
			else
				item.Save(System.Threading.Thread.CurrentPrincipal.Identity.Name);
		}

		#endregion
		#region Columns Struct
		public struct Columns
		{
			 public static string TemplateID = @"TemplateID";
			 public static string TemplateName = @"TemplateName";
			 public static string Picture1 = @"Picture1";
			 public static string Picture2 = @"Picture2";
			 public static string Picture3 = @"Picture3";
			 public static string DateAdded = @"DateAdded";
			 public static string DateModified = @"DateModified";
						
		}

		#endregion
	}

}

